package com.janlei.tdd.practise.model;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

import static com.janlei.tdd.practise.model.Sell.REBATE_1;
import static com.janlei.tdd.practise.model.Sell.REBATE_2;


@Getter
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
public class Product {
    private String name;
    private Double price;

    public String prefix() {
        return Sell.rebate(name);
    }

    public Double getRebate() {
        String prefix = prefix();
        if (REBATE_1.equals(prefix)) {
            return price * 0.9;
        }

        if (REBATE_2.equals(prefix)) {
            return price * 0.85;
        }

        return price;
    }
}


final class Sell {
    static final String REBATE_1 = "DIS_10";
    static final String REBATE_2 = "DIS_15";

    private Sell() {
    }

    public static String rebate(String name) {
        if (name.startsWith(REBATE_1)) {
            return REBATE_1;
        }

        if (name.startsWith(REBATE_2)) {
            return REBATE_2;
        }

        return name;
    }

}